package com.xagcdx.group1.service.impl;

import com.xagcdx.group1.bean.User;
import com.xagcdx.group1.dao.UserMapper;
import com.xagcdx.group1.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  鏈嶅姟瀹炵幇绫�
 * </p>
 *
 * @author grou1
 * @since 2020-06-09
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Autowired
private UserMapper userMapper;
public User login (String uname){
	   
	
    return  userMapper.login(uname);

}
public List<User> userlistPage(int page, int size, String uname , String rid){
    return userMapper.userListPage(page,size,uname ,rid );
};
public Integer counts(String uname , String rid){
    return userMapper.counts(uname,rid);
}


public   boolean updateUser(String uid,String uname,String account,String rid){
    return userMapper.updateUserInfo(uid, uname, account)&&userMapper.updateUserRole(uid,rid);
};
public  boolean addUser(String uname,String account,String rid){
	QueryWrapper<User> queryWrapper = new QueryWrapper<>();
	queryWrapper.eq("uname", uname);
    return userMapper.addUserInfo(uname, account) && userMapper.addUserRole(userMapper.selectOne(queryWrapper).getUid(),rid);
}

public String getRid(String uname) {
	// TODO Auto-generated method stub
	return userMapper.getRid(uname);
}
public String getlastuser() {
	// TODO Auto-generated method stub
	return userMapper.getlastuser();
}
public boolean savelog(String name) {
	// TODO Auto-generated method stub
	
	return userMapper.savelog(name,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(new Date()));
};
}
